package com.ocm.core.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Version;

@Entity
@Table(name = "PROPERTYDEF")
@NamedQueries( {
      @NamedQuery(name = PropertyDefinition.FIND_ALL, query = "SELECT propertyDef FROM PropertyDefinition propertyDef"),
      @NamedQuery(name = PropertyDefinition.FIND_NAME, query = "SELECT propertyDef FROM PropertyDefinition propertyDef WHERE propertyDef.name=:name and propertyDef.storage.id=:id"),
      @NamedQuery(name = PropertyDefinition.FIND_STORAGEID, query = "SELECT propertyDef FROM PropertyDefinition propertyDef WHERE propertyDef.storage.id=:id"),
      @NamedQuery(name = PropertyDefinition.FIND_ID_LIST, query = "SELECT propertyDef FROM PropertyDefinition propertyDef WHERE propertyDef.id IN (:listId)"),
      @NamedQuery(name = PropertyDefinition.FIND_NAME_LIST, query = "SELECT propertyDef FROM PropertyDefinition propertyDef WHERE propertyDef.name IN (:listName) and propertyDef.storage.id=:id")})
public class PropertyDefinition implements Persistable {

   public static final String FIND_ALL = "PropertyDefinition.FIND_ALL";

   public static final String FIND_NAME = "PropertyDefinition.FIND_NAME";

   public static final String FIND_ID_LIST = "PropertyDefinition.FIND_ID_LIST";

   public static final String FIND_STORAGEID = "PropertyDefinition.FIND_STORAGEID";

   public static final String FIND_NAME_LIST = "PropertyDefinition.FIND_NAME_LIST";

   public static final String NAME_PARA = "name";

   public static final String ID_PARA = "id";

   public static final String LIST_ID_PARA = "listId";

   public static final String LIST_NAME_PARA = "listName";

   public PropertyDefinition() {
      this.isHidden = false;
      this.readOnly = false;
   }

   @Id
   @GeneratedValue(strategy = GenerationType.TABLE, generator = "GEN_PROPERTYDEF")
   @TableGenerator(name = "GEN_PROPERTYDEF", table = "SEQUENCE_LIST", allocationSize = 1, initialValue = 1, pkColumnName = "NAME", valueColumnName = "NEXT_SEQUENCE", pkColumnValue = "PROPERTYDEF")
   @Column(name = "PROPERTYDEF_ID")
   private Long id;

   @Column(name = "PROPERTY_NAME", nullable = false)
   private String name;

   @Column(name = "DISPLAY_NAME")
   private String displayName;

   @Column(name = "MAXTH_LENGTH")
   private Integer maxlength;

   @Column(name = "HAS_MULTI_VALUE")
   private Boolean multiValue;

   @Column(name = "DESCRIPTION")
   private String description;

   @Column(name = "PROPERTY_TYPE")
   @Enumerated(EnumType.ORDINAL)
   private PropertyType propertyType;

   @Column(name = "READONLY")
   private Boolean readOnly;

   @Column(name = "HIDDEN")
   private Boolean isHidden;

   @Column(name = "EDITABLE")
   private Boolean editable;

   @Column(name = "DEFAULT_VALUE")
   private String defaultValue;

   @Column(name = "OBJECT_CONFIG")
   private String objectConfig;

   @Version
   @Column(name = "VERSION_NO")
   private Long version;

   @Column(name = "STATUS_NO")
   @Enumerated(EnumType.ORDINAL)
   private Status status;

   @ManyToOne
   @JoinColumn(name = "STORAGE_ID")
   private Storage storage;

   @Column(name = "CREATED_USER")
   private String createdUser;

   @Column(name = "CREATED_DATE")
   private Date createdDated;

   @Column(name = "MODIFYED_USER")
   private String modifyedUser;

   @Column(name = "MODIFYED_DATE")
   private Date modifyedDated;

   public Long getId() {
      return id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public String getDescription() {
      return description;
   }

   public void setDescription(String description) {
      this.description = description;
   }

   public PropertyType getPropertyType() {
      return propertyType;
   }

   public void setPropertyType(PropertyType propertyType) {
      this.propertyType = propertyType;
   }

   public Status getStatus() {
      return status;
   }

   public void setStatus(Status status) {
      this.status = status;
   }

   public String getDisplayName() {
      return displayName;
   }

   public void setDisplayName(String displayName) {
      this.displayName = displayName;
   }

   public Integer getMaxlength() {
      return maxlength;
   }

   public void setMaxlength(Integer maxlength) {
      this.maxlength = maxlength;
   }

   public Boolean isMultiValue() {
      return multiValue;
   }

   public void setMultiValue(Boolean multiValue) {
      this.multiValue = multiValue;
   }

   public Storage getStorage() {
      return storage;
   }

   public void setStorage(Storage storage) {
      this.storage = storage;
   }

   public Boolean getReadOnly() {
      return readOnly;
   }

   public void setReadOnly(Boolean readOnly) {
      this.readOnly = readOnly;
   }

   public Boolean getIsHidden() {
      return isHidden;
   }

   public void setIsHidden(Boolean isHidden) {
      this.isHidden = isHidden;
   }

   public String getDefaultValue() {
      return defaultValue;
   }

   public Boolean getEditable() {
      return editable;
   }

   public void setEditable(Boolean editable) {
      this.editable = editable;
   }

   public void setDefaultValue(String defaultValue) {
      this.defaultValue = defaultValue;
   }

   public String getCreatedUser() {
      return createdUser;
   }

   public void setCreatedUser(String createdUser) {
      this.createdUser = createdUser;
   }

   public Date getCreatedDated() {
      return createdDated;
   }

   public void setCreatedDated(Date createdDated) {
      this.createdDated = createdDated;
   }

   public String getModifyedUser() {
      return modifyedUser;
   }

   public void setModifyedUser(String modifyedUser) {
      this.modifyedUser = modifyedUser;
   }

   public Date getModifyedDated() {
      return modifyedDated;
   }

   public void setModifyedDated(Date modifyedDated) {
      this.modifyedDated = modifyedDated;
   }

   public String getObjectConfig() {
      return objectConfig;
   }

   public void setObjectConfig(String objectConfig) {
      this.objectConfig = objectConfig;
   }

   @Override
   public String toString() {
      StringBuffer stringBuffer = new StringBuffer(PropertyDefinition.class.getName());
      stringBuffer = stringBuffer.append("{id=" + id + ",");
      stringBuffer = stringBuffer.append("{name=" + name + ",");
      stringBuffer = stringBuffer.append("{version=" + version + "}");
      return stringBuffer.toString();
   }

   @Override
   public boolean equals(Object obj) {
      PropertyDefinition propertyCompare = (PropertyDefinition) obj;
      if (this.getId().longValue() == propertyCompare.getId().longValue()) {
         return true;
      }
      return false;
   }
}
